home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Testing & Debugging / Debuggers & dcmds / MacsBug 6.5.2 / dcmds / C Samples / Echo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-26  |  2.2 KB  |  113 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Echo.c
  3.  
  4.     Contains:    A sample dcmd which echos all command line parameters.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.  
  8.     Copyright:    © 1988, 1994 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <3>   10-Dec-94    JM3        Updated for new format 3 dcmd requirements.
  13.          <2>    1-Sep-94    JM3        Included string.h so we build with no warnings with -r.
  14.  
  15. */
  16.  
  17.  
  18. #include <Memory.h>
  19. #include <Types.h>
  20. #include <string.h>
  21.  
  22. #include "dcmd.h"
  23.  
  24. void NumberToHex (long number, Str255 hex)
  25. {
  26.  
  27.     Str255    digits = "0123456789ABCDEF";
  28.     int        n;
  29.  
  30.     strcpy (hex, &".00000000");
  31.     hex[0] = 8;
  32.     for (n = 8; n >= 1; n--)
  33.     {
  34.         hex[n] = digits[number % 16];
  35.         number = number / 16;
  36.     }
  37.  
  38. } // NumberToHex
  39.  
  40.  
  41. pascal void CommandEntry (dcmdBlock* paramPtr)
  42. {
  43.  
  44.     short    pos, ch;
  45.     long    value;
  46.     Boolean    ok;
  47.     Str255    str;
  48.  
  49.     static const char usageStr[] = "\p[params...]";
  50.  
  51.     switch (paramPtr->request)
  52.     {
  53.         case dcmdInit:
  54.             break;
  55.  
  56.         case dcmdHelp:
  57.             dcmdDrawLine("\pEcho the command line parameters");
  58.             break;
  59.  
  60.         case dcmdGetInfo:
  61.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  62.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  63.             break;
  64.  
  65.         case dcmdDoIt:
  66.             do
  67.             {
  68.                 // Save the position so we can rewind if we get an error
  69.             
  70.                 pos = dcmdGetPosition ();
  71.                 ch  = dcmdPeekAtNextChar ();
  72.  
  73.                 if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')))
  74.                 {
  75.                     // Get the parameter as a text string
  76.  
  77.                     ch = dcmdGetNextParameter (str);
  78.                     dcmdDrawLine (str);
  79.  
  80.                 }
  81.                 else
  82.                 {
  83.                     // Get the parameter as a 32 bit value
  84.  
  85.                     ch = dcmdGetNextExpression (&value, &ok);
  86.  
  87.                     if (ok)
  88.                     {    
  89.                         // The expression was parsed correctly
  90.  
  91.                         NumberToHex (value, str);
  92.                         dcmdDrawLine (str);
  93.  
  94.                     }
  95.                     else
  96.                     {    
  97.                         // The expression contained an error. Get it as a string
  98.  
  99.                         dcmdSetPosition (pos);
  100.                         ch = dcmdGetNextParameter (str);
  101.                         dcmdDrawLine (str);
  102.                     }
  103.                 }
  104.             } while (ch != '\n');
  105.                 break;
  106.  
  107.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  108.     
  109.         default:
  110.             break;
  111.     }
  112. } // CommandEntry
  113.